﻿using System;
using System.Text;
using System.Collections;
using System.Xml;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Threading;

using Telerik.WebControls;
using UFSoft.UBF.UI.WebControls;
using UFSoft.UBF.UI.Controls;
using UFSoft.UBF.Util.Log;
using UFSoft.UBF.Util.Globalization;

using UFSoft.UBF.UI.IView;
using UFSoft.UBF.UI.Engine;
using UFSoft.UBF.UI.MD.Runtime;
using UFSoft.UBF.UI.ActionProcess;
using UFSoft.UBF.UI.WebControls.ClientCallBack;
using UFIDA.U9.UI.PDHelper;
using UFSoft.UBF.UI.FormProcess;
using UFIDA.U9.Base.Profile.Proxy;
using UFSoft.UBF.UI.ControlModel;
using UFIDA.U9.Base.Profile;
using UFSoft.UBF.UI.WebControls.Association;
using UFSoft.UBF.UI.WebControls.Association.Adapter;
using System.Collections.Specialized;
using UFSoft.UBF.UI.WebControlAdapter;
using System.Web;


/***********************************************************************************************
 * Form ID: 
 * UIFactory Auto Generator 
 ***********************************************************************************************/
namespace UFIDA.U9.Cust.U9Demo.DeliverUI
{
    public partial class DeliverUIFormWebPart
    {
        #region Custome eventBind
	
		 
				//BtnSave_Click...
		private void BtnSave_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnSave_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnCancel_Click...
		private void BtnCancel_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnCancel_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnAdd_Click...
		private void BtnAdd_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnAdd_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnDelete_Click...
		private void BtnDelete_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnDelete_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnCopy_Click...
		private void BtnCopy_Click_Extend(object sender, EventArgs  e)
		{
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.

            this.Model.Delivery.FocusedRecord.DocNo = "";
            this.Model.Delivery.FocusedRecord.Status = 0;

            BtnCopy_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnSubmit_Click...
		private void BtnSubmit_Click_Extend(object sender, EventArgs  e)
		{
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.

            StatusUpdate();
            BtnSubmit_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnApprove_Click...
		private void BtnApprove_Click_Extend(object sender, EventArgs  e)
		{
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.

            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
            if (this.Model.Delivery.FocusedRecord.DocumentType_ApproveType.Value == 1)
            {
                UFIDA.U9.UI.PDHelper.PDPopWebPart.ApproveFlow_ApproveBatchUIWebPart(this);//工作流审批
            }
            else
            {
                StatusUpdate();
            }
            BtnApprove_Click_DefaultImpl(sender,e);
		}

        private void BtnUndoApprove_Click_Extend(object sender, EventArgs e)
        {
            StatusUpdate();
            BtnUndoApprove_Click_DefaultImpl(sender, e);
        }
        private void StatusUpdate()
        {
            if (this.Model.Delivery.FocusedRecord != null && this.Model.Delivery.FocusedRecord.ID > 0)
            {
                UFIDA.U9.Cust.U9Demo.DeliveryBP.Proxy.StatusUpdateProxy proxy = new DeliveryBP.Proxy.StatusUpdateProxy();
                proxy.ID = this.Model.Delivery.FocusedRecord.ID;
               // proxy.Status = this.Model.Delivery.FocusedRecord.Status ?? 0;
                proxy.Version = this.Model.Delivery.FocusedRecord.SysVersion ?? 0;
                proxy.Do();
                this.Action.NavigateAction.Refresh(null);
            }
        }

        //BtnFind_Click...
        private void BtnFind_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnFind_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnList_Click...
		private void BtnList_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnList_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnFirstPage_Click...
		private void BtnFirstPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnFirstPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnPrevPage_Click...
		private void BtnPrevPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnPrevPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnNextPage_Click...
		private void BtnNextPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnNextPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnLastPage_Click...
		private void BtnLastPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnLastPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnAttachment_Click...
		private void BtnAttachment_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnAttachment_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnFlow_Click...
		private void BtnFlow_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnFlow_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnOutput_Click...
		private void BtnOutput_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnOutput_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnPrint_Click...
		private void BtnPrint_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnPrint_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnOk_Click...
		private void BtnOk_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnOk_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnClose_Click...
		private void BtnClose_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnClose_Click_DefaultImpl(sender,e);
		}	
		 
				//OnPullPO720_Click...
	
		 /// <summary>
         /// 推单，生成收货单数据
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
		//OnPushRcv130_Click...
		private void OnPushRcv130_Click_Extend(object sender, EventArgs  e)
		{
            //UFSoft.UBF.UI.AtlasHelper.RegisterAtlasStartupScript(this.Page, this.Page.GetType(),
            //"JavaScriptExecQueue", "window.open('http://www.baidu.com');", true);
            
            //UFIDA.U9.CUST.LMZ.U9DataForCRMService.Proxy.PersonTOCRMProxy proxy = new CUST.LMZ.U9DataForCRMService.Proxy.PersonTOCRMProxy();
            //proxy.Do();
            
            //UFSoft.UBF.UI.AtlasHelper.RegisterAtlasStartupScript(this.Page, this.Page.GetType(), "JavaScriptExecQueue", "<script>window.open('http://www.baidu.com','_blank')</script>", true);
            //System.Web.HttpContext.Current.Response.Redirect("http://www.baidu.com",true);
            
            //System.Web.HttpContext.Current.Response.Write("<script>window.location='http://www.baidu.com';</script>");
            //System.Web.HttpContext.Current.Response.Write("<script>window.open('http://www.baidu.com','_blank')</script>");//——原窗口保留，另外新增一个新页面;
            
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
            //PDContext context = UFIDA.U9.UI.PDHelper.PDContext.Current;
            ////弹窗列表
            //NameValueCollection param = new NameValueCollection();
            //if (this.Model.Delivery.FocusedRecord != null && this.Model.Delivery.FocusedRecord.ID > 0)
            //{
            //    param.Add("DeliveryID", this.Model.Delivery.FocusedRecord.ID.ToString());
            //}
            //else
            //    throw new Exception("请选择数据！");
            //this.ShowAtlasModalDialog(this.btnBack, "d0a80516-82ef-490b-af78-832199180e39", "生成收货单数据", "992", "504", this.TaskId.ToString(), param, false, false, false);
            OnPushRcv130_Click_DefaultImpl(sender,e);
		}


        private void DocumentType104_TextChanged_Extend(object sender, EventArgs e)
        {
            DocumentType104_TextChanged_DefaultImpl(sender, e);
        }

        /// <summary>
        /// 参照拉单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPullPORef381_Click_Extend(object sender, EventArgs e)
        {
           
            if (this.Model.Delivery.FocusedRecord != null && this.Model.Delivery.FocusedRecord.DocumentType > 0)
            {
                this.CurrentState["DucumentTypeID"] = (this.Model.Delivery.FocusedRecord.DocumentType ?? 0).ToString();
            }
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
            //弹窗列表
            //this.ShowAtlasModalDialog(this.btnBack, "b0c5979b-8b3c-49d5-b6c2-5ad1d4b8c2aa", "拉取采购订单数据", "580", "408", this.TaskId.ToString(), null, false, false, false);
            OnPullPORef381_Click_DefaultImpl(sender, e);
        }

        /// <summary>
        /// 列表参照
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPullPOList_Click_Extend(object sender, EventArgs e)
        {
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.


            //弹窗列表
            NameValueCollection param = new NameValueCollection();
            if (this.Model.Delivery.FocusedRecord != null && this.Model.Delivery.FocusedRecord.DocumentType > 0)
            {
                param.Add("DucumentTypeID", (this.Model.Delivery.FocusedRecord.DocumentType ?? 0).ToString());
            }
            this.ShowAtlasModalDialog(this.btnBack, "d94687b8-338d-4eb5-9f6e-4158fc7d919d", "拉取采购订单数据", "992", "504", this.TaskId.ToString(), param, false, false, false);
            //弹出库存报表
            //NameValueCollection param = new NameValueCollection();
            //param.Add("Function", "1");
            //param.Add("Format", "1");
            //param.Add("sId", "3017");
            //this.CurrentState["ABC"] = "ABC";
            //this.CurrentSessionState["ABCD"] = "ABCD";
            //弹出标准库存报表
            //this.ShowAtlasModalDialog(this.btnBack, "9cb66ad1-eca2-4422-bac2-730fd681ca27", "库存报表", "992", "504", this.TaskId.ToString(), param, false, false, false);
            //弹出报表模式开发的报表
            //NameValueCollection param = new NameValueCollection();
            //param.Add("ReportContent", "7d8c164f-849c-4aef-bf20-55c83ed75df7");
            //System.Web.HttpContext.Current.Session["ABC"] = "ABCD";
            ////param.Add("ABC", "ABCD");
            ////this.CurrentState["ABC"] = "ABC";
            ////this.CurrentSessionState["ABCD"] = "ABCD";
            //this.ShowAtlasModalDialog(this.btnBack, "b18448a9-ea97-4216-8a4f-5deed62b49e4", "SQL开发报表", "992", "504", this.TaskId.ToString(), param, false, false, false);
            OnPullPOList_Click_DefaultImpl(sender, e);
        }

        /// <summary>
        /// 自定义视图拉单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPullPOCust_Click_Extend(object sender, EventArgs e)
        {
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
            //自定义视图弹窗
            NameValueCollection param = new NameValueCollection();
            if (this.Model.Delivery.FocusedRecord != null && this.Model.Delivery.FocusedRecord.DocumentType > 0)
            {
                param.Add("DucumentTypeID", (this.Model.Delivery.FocusedRecord.DocumentType ?? 0).ToString());
            }
            this.ShowAtlasModalDialog(this.btnBack, "44106060-c552-4f16-a611-a3107c682079", "拉取采购订单数据", "872", "448", this.TaskId.ToString(), param, false, false, false);

            OnPullPOCust_Click_DefaultImpl(sender, e);
        }

        /// <summary>
        /// 回调按钮，弹窗创建单据后，使用回调按钮加载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBack_Click_Extend(object sender, EventArgs e)
        {
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.

            if(this.CurrentState["DeliveryID"] != null && !String.IsNullOrEmpty(this.CurrentState["DeliveryID"].ToString()))
            {
                //调整到指定ID的单据
                this.Action.NavigateAction.MovePageAt(null, Convert.ToInt64(this.CurrentState["DeliveryID"].ToString()));
                this.CurrentState["DeliveryID"] = null;
            }
            btnBack_Click_DefaultImpl(sender, e);
        }

        #region 自定义数据初始化加载和数据收集
        private void OnLoadData_Extend(object sender)
		{	
			OnLoadData_DefaultImpl(sender);
		}
		private void OnDataCollect_Extend(object sender)
		{	
			OnDataCollect_DefaultImpl(sender);
		}
		#endregion  

        #region 自己扩展 Extended Event handler 
		public void AfterOnLoad()
		{

		}

        public void AfterCreateChildControls()
        {
            //开启个性化     
            UFIDA.U9.UI.PDHelper.PersonalizationHelper.SetPersonalizationEnable((BaseWebForm)this, true);

            //查询按钮设置
            PDFormMessage.ShowConfirmDialog(this.Page, "e7686aaf-26a4-4886-abf2-0b046253fe6e", "580", "408",
                            Title, wpFindID.ClientID, this.BtnFind, null);

            //参照拉单PO
            UI.PDHelper.PDFormMessage.ShowConfirmDialog(this.Page, "b0c5979b-8b3c-49d5-b6c2-5ad1d4b8c2aa", "580", "408",
                            Title, wpFindID.ClientID, this.OnPullPORef381, null);

            //弹性域设置
            //this.FlexFieldPicker0为表头弹性域处理，需要在UIForm中拖出弹性域控件
            FlexFieldHelper.SetDescFlexField(new DescFlexFieldParameter[] { new DescFlexFieldParameter(this.FlexFieldPicker0, this.Model.Delivery) });
            //表体弹性域处理，需要UIForm中表体最后一列添加一个Text的列。平台代码自动实现，“DescFlexField”名称需要和后台BE对应字段名称完全一致
            FlexFieldHelper.SetDescFlexField(this.DataGrid9, this.DataGrid9.Columns.Count - 1, "DescFlexField");

            //取得提示信息资源：是否删除当前记录
            string message = PDResource.GetDeleteConfirmInfo();
            //绑定注册弹出对话框到删除按钮
            PDFormMessage.ShowConfirmDialog(this.Page, message, "", this.BtnDelete);
            PDFormMessage.ShowConfirmDialog(this.Page, "确认放弃当前记录？", "", this.BtnCancel);

            //设置默认行号
            GetProfileValueProxy bpObj = new GetProfileValueProxy();
            //需要添加引用：..\U9.VOB.Product.Component\UBF\UFIDA.U9.Base.BaseBP.Deploy.dll
            //和UFIDA.U9.Base.BaseBP.Agent.dll文件。
            bpObj.ProfileCode = "SysLineNo";
            PVDTOData pVTDOData = bpObj.Do();
            //行GRID
            ((IAutoRowNo)this.DataGrid9.Columns["DocLineNo"]).Sequence = true;//RowNo对应行号的字段
            ((IAutoRowNo)this.DataGrid9.Columns["DocLineNo"]).SequenceStep = Int32.Parse(pVTDOData.ProfileValue);
            ((IAutoRowNo)this.DataGrid9.Columns["DocLineNo"]).SequenceStart = Int32.Parse(pVTDOData.ProfileValue);

            // for(int i=0;i<this.DataGrid9.Columns.Count;i++)
            //{
            //    var column = this.DataGrid9.Columns[i];
            //    ((IUFFldReferenceColumn)column).AddReferenceInParameter("", "", "");
            //    ((IUFFldReferenceColumn)column).RefRelations.Add(new UFRefRelationAdapter("", "", ""));
            //}

            ((UFWebDataGridAdapter)this.DataGrid9).IsShowPageSizeSetting = true;
            ((UFWebDataGridAdapter)this.DataGrid9).AllowSelectAllPage = true;

            //注册postback事件，多选料品是新增行（新增行只能用postback)
            RegisterGridCellDataChangedPostBack();
            //注册callback事件，单价、数量计算金额(改变行中字段的值，postback,callback都可以使用)
            RegisterGridCellDataChangedCallBack();
        }

        public void AfterEventBind()
        {
        }
        
		public void BeforeUIModelBinding()
		{
            this.DocumentType104.CustomInParams = BaseAction.Symbol_AddCustomFilter + "= BizType=0";
            //值集过滤方法
            //this.Deliver128.CustomInParams = BaseAction.Symbol_AddCustomFilter + "= ValueSetDef.Code='AF01'";
            //行值集过滤方法
            //IUFFldReferenceColumn faultType = this.DataGrid1.Columns["FaultType"] as IUFFldReferenceColumn;
            //faultType.CustomInParams = BaseAction.Symbol_AddCustomFilter + "= ValueSetDef.Code='AF02'";
            //水印
            SetWaterMark(this.Model.Delivery, "Status", this.Status149);
            //参照拉单后需要根据生单的ID加载数据，
            LoadData();
        }
        /// <summary>
        /// 参照拉单后需要根据生单的ID加载数据
        /// </summary>
        private void LoadData()
        {
            if (this.CurrentState["DeliveryID"] != null && !String.IsNullOrEmpty(this.CurrentState["DeliveryID"].ToString()))
            {
                string oPath = "  ID =" + this.CurrentState["DeliveryID"] + "";
                this.CurrentState["DeliveryID"] = null;
                this.Model.Delivery.Clear();
                this.Model.Delivery.CurrentFilter.OPath = oPath;
                this.Action.CommonAction.Load(this.Model.Delivery, this.Model.Delivery_DeliveryLine);
            }
        }

        public void AfterUIModelBinding()
		{
            SetControlStatus();
            SetDocNoControlStatus();//根据单据类型设置单号状态
            //系统参数设置只读
            ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.Status149).ReadOnly = true;

            this.BtnOk.Visible = false;
            this.BtnClose.Visible = false;
        }

        /// <summary>
        ///  根据单据类型设置单号状态
        /// </summary>
        private void SetDocNoControlStatus()
        {
            //调用BP获取默认单据类型
            UFIDA.U9.Cust.U9Demo.DeliveryBP.Proxy.GetDefalueDocTypeProxy proxy = new DeliveryBP.Proxy.GetDefalueDocTypeProxy();
            //proxy.ID = this.Model.ProductPubChangeApply.FocusedRecord.ProductDocType??0;
            proxy.ID = Convert.ToInt64(this.DocumentType104.Key);
            UFIDA.U9.Cust.U9Demo.DeliveryBP.DocTypeDTOData amDocType = proxy.Do();
            if (amDocType == null)
            {
                return;
            }
            if (amDocType.DocHeadSequenceStyle == 1)//手工编号
            {
                if (this.Model.Delivery.FocusedRecord != null)
                {
                    this.Model.Delivery.FocusedRecord.DocNo = "";
                }
                ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.DocNo70).ReadOnly = false;
            }
            else if (amDocType.DocHeadSequenceStyle == 0)
            {

                ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.DocNo70).ReadOnly = true;
                if (this.Model.Delivery.FocusedRecord != null)
                {
                    if (this.Model.Delivery.FocusedRecord.DocNo.Trim() == "")
                    {
                        this.Model.Delivery.FocusedRecord.DocNo = "自动编号";
                    }
                }
            }
        }

        #region 控制按钮状态
        ///<summary>
        /// 控制按钮状态
        ///</summary>
        private void SetControlStatus()
        {
            //如果页面是通过TitleLink进入则显示确定取消按钮
            if (NavigateManager.IsTitleLink(this))
            {
                this.BtnOk.Visible = true;
                this.BtnClose.Visible = true;

            }
            else
            {
                this.BtnOk.Visible = false;
                this.BtnClose.Visible = false;

            }
            this.DataBind();
            this.DataCollect();
            //单据类型自动编号，单号控件不可用；单据类型手工编号，单号控件可用
            if (this.Model.Delivery.FocusedRecord != null)
            {
                if (this.Model.Delivery.FocusedRecord.DocumentType_DocHeaderSequenceStyle == 0)
                    ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.DocNo70).ReadOnly = true;
                else
                    ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.DocNo70).ReadOnly = false;
            }

            if (this.Model.Delivery.FocusedRecord.ID < 0L)
                this.Card3.ReadOnly = false;
            else if (this.Model.Delivery.FocusedRecord.Status >= 2)
                this.Card3.ReadOnly = true;
            this.Toolbar2.Enabled = true;
            //下列暂时隐藏      
            this.BtnCopy.Enabled = true;//复制
            this.BtnSubmit.Enabled = true;
            this.BtnApprove.Enabled = true;
            this.BtnUndoApprove.Enabled = true;// 弃审
            this.BtnDelete.Enabled = true;
            this.BtnSave.Enabled = true;

            //Opened 0     System::Int32  开立  
            //Approving 1  System::Int32  审核中  
            //Approved 2   System::Int32  已审核  
            switch (this.Model.Delivery.FocusedRecord.Status)
            {
                case -1:
                case 0:
                    this.BtnApprove.Enabled = false;
                    this.BtnUndoApprove.Enabled = false;
                    if (this.Model.Delivery.FocusedRecord.ID < 1)
                    {
                        this.BtnCopy.Enabled = false;
                        this.BtnSubmit.Enabled = false;
                    }
                    break;
                case 1:
                    this.BtnSubmit.Enabled = false;
                    this.BtnApprove.Enabled = true;
                    this.BtnUndoApprove.Enabled = false;
                    //this.BtnSave.Enabled = false;

                    break;
                case 2:
                    this.BtnSubmit.Enabled = false;
                    this.BtnApprove.Enabled = false;
                    this.BtnDelete.Enabled = false;
                    this.BtnSave.Enabled = false;
                    break;
                case 3:
                    this.Toolbar2.Enabled = false;
                    break;
                default:
                    break;
            }
             ((UFSoft.UBF.UI.ControlModel.IUIFieldBindingDataBindControl)this.DocNo70).ReadOnly = true;


        }
        #endregion

        #region 设置水印
        public static void SetWaterMark(UFSoft.UBF.UI.MD.Runtime.IUIView ModelView, string StatusName, IUFFldDropDownList IUIDocStatus)
        {
            UFWaterMark waterMark = new UFWaterMark();
            waterMark.TargetControl = IUIDocStatus;
            if (ModelView.FocusedRecord != null)
            {
                if ((int)ModelView.FocusedRecord[StatusName] == 2)
                { waterMark.WaterMarkType = enuMarkType.Approved; }
                else if ((int)ModelView.FocusedRecord[StatusName] == 1)
                { waterMark.WaterMarkType = enuMarkType.Approving; }
                else if ((int)ModelView.FocusedRecord[StatusName] == 0)
                { waterMark.WaterMarkType = enuMarkType.Open; }
                else
                { waterMark.WaterMarkType = enuMarkType.Open; }
            }
     
        }
        #endregion


        #region postback 料品多选新增行
        /// <summary>
        /// 注册表格单元格内容改变的回调事件
        /// </summary>
        private void RegisterGridCellDataChangedPostBack()
        {
            AssociationControl assocControl = new AssociationControl();
            assocControl.SourceServerControl = this.DataGrid9;
            assocControl.SourceControl.EventName = "OnCellDataValueChanged";
            ((IUFClientAssoGrid)assocControl.SourceControl).FireEventCols.Add("Item");
            CodeBlock cb = new CodeBlock();
            UFWebClientGridAdapter gridAdapter = new UFWebClientGridAdapter(this.DataGrid9);
            gridAdapter.IsPostBack = true;
            gridAdapter.PostBackTag = "OnCellDataValueChanged";
            cb.TargetControls.addControl(gridAdapter);
            assocControl.addBlock(cb);
            UFGrid itemGrid = this.DataGrid9 as UFGrid;
            itemGrid.GridCustomerPostBackEvent += new GridCustomerPostBackDelegate(GridCellOnChanged_DoCustomerAction_Grid);
        }

        /// <summary>
        /// 表格的CallBack处理方式
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private void GridCellOnChanged_DoCustomerAction_Grid(object sender, GridCustomerPostBackEventArgs e)
        {
            //检验参照返回缓冲数据是否为空
            if (this.CurrentState["CustItem_Table"] == null)
            {
               
                return;
            }
            this.DataGrid9.CollectData();
            this.DataGrid9.BindData();
            DataTable dt = this.CurrentState["CustItem_Table"] as DataTable;
            CurrentState.Remove("CustItem_Table");
            //校验DT是否为空
            if (dt == null || dt.Rows.Count < 1)
            {
                this.DataGrid9.CollectData();
                this.DataGrid9.BindData();
                return;
            }
            //获取最后的行号
            int rowNo = 10;
            int recordsCount = this.Model.Delivery_DeliveryLine.RecordCount;
            if (recordsCount != 0)
            {
                rowNo = Convert.ToInt32(this.Model.Delivery_DeliveryLine.Records[recordsCount - 1]["DocLineNo"]);
            }
            //定义字段
            string GiftCode = string.Empty;
            //若只返回一条，做数据收集即可
            if (dt.Rows.Count > 0)
            {
                Delivery_DeliveryLineRecord rd = this.Model.Delivery_DeliveryLine.FocusedRecord;
                if(rd == null)
                    rd = this.Model.Delivery_DeliveryLine.AddNewUIRecord();
                rd.Uom = Convert.ToInt64(dt.Rows[0]["PurchaseUOM_ID"]);
                rd.Uom_Code = dt.Rows[0]["PurchaseUOM_Code"].ToString();
                rd.Uom_Name = dt.Rows[0]["PurchaseUOM_Name"].ToString();
                //DataGrid9.CollectData();
                //DataGrid9.BindData();
            }
            //循环传回来的表体,//当多选参照界面点击确定返回时,Model默认添加了第一条记录,故不做处理
            for (int i = 1; i < dt.Rows.Count; i++)
            {
                rowNo += 10;
                Delivery_DeliveryLineRecord rd = this.Model.Delivery_DeliveryLine.AddNewUIRecord();
                rd.DocLineNo = rowNo;
                rd.Item = Convert.ToInt64(dt.Rows[i]["ID"]);
                rd.Item_Code = dt.Rows[i]["Code"].ToString();
                rd.Item_Name = dt.Rows[i]["Name"].ToString();
                rd.Uom = Convert.ToInt64(dt.Rows[i]["PurchaseUOM_ID"]);
                rd.Uom_Code = dt.Rows[i]["PurchaseUOM_Code"].ToString();
                rd.Uom_Name = dt.Rows[i]["PurchaseUOM_Name"].ToString();
                rd.SetParentRecord(this.Model.Delivery.FocusedRecord);
               
            }
            this.DataCollect();
            this.DataBind();

            DataGrid9.CollectData();
            DataGrid9.BindData();
        }
        #endregion


        #region callBack 单价、数量改变计算金额
        /// <summary>
        /// 注册表格单元格内容改变的回调事件
        /// </summary>
        private void RegisterGridCellDataChangedCallBack()
        {
            AssociationControl gridCellDataChangedASC = new AssociationControl();       //基本固定代码
            gridCellDataChangedASC.SourceServerControl = this.DataGrid9;
            gridCellDataChangedASC.SourceControl.EventName = "OnCellDataChanged";


            //CallBack处理方案
            ((IUFClientAssoGrid)gridCellDataChangedASC.SourceControl).FireEventCols.Add("Price");
            ((IUFClientAssoGrid)gridCellDataChangedASC.SourceControl).FireEventCols.Add("Qty");
            ClientCallBackFrm gridCellDataChangedCBF = new ClientCallBackFrm();
            gridCellDataChangedCBF.ParameterControls.Add(this.DataGrid9);

            gridCellDataChangedCBF.DoCustomerAction += new ClientCallBackFrm.ActionCustomer(gridCellDataChangedCBF_DoCustomerActionOfSubvillage);
            gridCellDataChangedCBF.Add(gridCellDataChangedASC);
            this.Controls.Add(gridCellDataChangedCBF);

        }

        /// <summary>
        /// 表格的CallBack处理方式
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private object gridCellDataChangedCBF_DoCustomerActionOfSubvillage(CustomerActionEventArgs args)
        {
            UFWebClientGridAdapter grid = new UFWebClientGridAdapter(this.DataGrid9);

            //取表格数据（当前行）
            ArrayList list = (ArrayList)args.ArgsHash[UFWebClientGridAdapter.ALL_GRIDDATA_SelectedRows]; //基本固定代码
            int curIndex = int.Parse(list[0].ToString());
            Hashtable table = (Hashtable)((ArrayList)args.ArgsHash[this.DataGrid9.ClientID])[curIndex];
            decimal qty = long.Parse(table["Qty"].ToString());
            decimal price = long.Parse(table["Price"].ToString());
            //可以调用BP获取数据赋值到界面上，可以料品改变时调用BP获取数据赋值到页面上等等。
            decimal amount = qty * price;
            //单价*数量=金额
            grid.CellValue.Add(new object[] { curIndex, "Amount", new string[] { amount.ToString(), amount.ToString(), amount.ToString() } });
            args.ArgsResult.Add(grid.ClientInstanceWithValue);
            return args;
        }
        #endregion

        #endregion
        #endregion

    }
}